﻿@page "/identity/user-roles/{Id}"
@attribute [Authorize(Policy = Permissions.Roles.View)]
@inject Microsoft.Extensions.Localization.IStringLocalizer<UserRoles> _localizer
@using BlazorHero.CleanArchitecture.Application.Responses.Identity
@using Microsoft.AspNetCore.Components

<HeroTitle Title="@Title" Description="@Description" />
@if (!_loaded)
{
    <MudProgressCircular Color="Color.Primary" Indeterminate="true" />
}
else
{
    <MudTable Hover="true" Elevation="25" Items="UserRolesList" Dense="@_dense" Bordered="@_bordered" Striped="@_striped" Filter="new Func<UserRoleModel, bool>(Search)" @bind-userRole="_userRole">
        <ToolBarContent>
            <div class="justify-center mud-text-align-center">
                @if (_canEditUsers)
                {
                    <MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-auto" OnClick="SaveAsync" ButtonType="ButtonType.Submit">@_localizer["Update User Roles"]</MudButton>
                }
            </div>
            <MudSpacer />
            @if (_canSearchRoles)
            {
                <MudTextField @bind-Value="_searchString" Immediate="true" FullWidth=false Placeholder="@_localizer["Search For User Roles"]" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0 mb-3"></MudTextField>
            }
        </ToolBarContent>
        <HeaderContent>
            <MudTh><MudTableSortLabel SortBy="new Func<UserRoleModel, object>(x => x.RoleName)">@_localizer["Role Name"]</MudTableSortLabel></MudTh>
            <MudTh><MudTableSortLabel SortBy="new Func<UserRoleModel, object>(x => x.RoleDescription)">@_localizer["Description"]</MudTableSortLabel></MudTh>
            <MudTh><MudTableSortLabel SortBy="new Func<UserRoleModel, object>(x => x.Selected)">@_localizer["Status"]</MudTableSortLabel></MudTh>
        </HeaderContent>
        <RowTemplate>
            <MudTd DataLabel="@_localizer["Role Name"]">
                <MudHighlighter Text="@context.RoleName" HighlightedText="@_searchString" />
            </MudTd>
            <MudTd DataLabel="@_localizer["Description"]">
                <MudHighlighter Text="@context.RoleDescription" HighlightedText="@_searchString" />
            </MudTd>
            <MudTd DataLabel="Role"><MudCheckBox @bind-Checked="@context.Selected" Disabled="@(!_canEditUsers)" Color="Color.Secondary"></MudCheckBox></MudTd>
        </RowTemplate>
        <FooterContent>
            <MudSwitch @bind-Checked="@_dense" Color="Color.Secondary" Style="margin-left: 5px;">@_localizer["Dense"]</MudSwitch>
            <MudSwitch @bind-Checked="@_striped" Color="Color.Tertiary" Style="margin-left: 5px;">@_localizer["Striped"]</MudSwitch>
            <MudSwitch @bind-Checked="@_bordered" Color="Color.Warning" Style="margin-left: 5px;">@_localizer["Bordered"]</MudSwitch>
        </FooterContent>
        <PagerContent>
            <TablePager />
        </PagerContent>
    </MudTable>
}